<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
 @session_start();
/*   Description  of this file
 *    Author king-of-war
 *    Last Modified 2009-5-6
 *    This class designed  for the *** operation
 */
$root_path = '../';
include_once $root_path . 'admin/smarty_config.php';
include_once $root_path . 'admin/class/vote.class.php';
include_once $root_path . 'admin/class/error.class.php';
$vote = new vote($root_path);
$error = new Errmsg();

/*
 *
 * check identify
 */
include_once $root_path.'admin/class/verify.class.php';
$a=new verify($root_path);
$a->identity_check(3);
/*
 * check the id which has been choosed or none
 */
if ($_GET['id'] != '') {
	$id = $_GET['id'];
} else {
	$info = '请选择要编辑的投票项目';
	$error->error_chinese($info);
	exit;
}
/*
 * read the sort_se & replace id with topic
 */
$a = $vote->vote_read($id, 3);
$vote_id = $a[0]->get_vote_id();
$pass = $vote->vote_read($vote_id, 1);
$topic = $pass[0]->get_topic();
/*
 * set votes pass data to template
 */
$votes['id'] = $id;
$votes['topic'] = $topic;
$votes['se_id'] = $a[0]->get_se_id();
$votes['contant'] = $a[0]->get_contant();
/*
 *   get all topic
 */
$a = $vote->vote_read('', 1);
$max = count($a);
$topics = array ();
for ($i = 0; $i < $max; $i++) {
	$topics[$i]['id'] = $a[$i]->get_id();
	$topics[$i]['topic'] = $a[$i]->get_topic();
}

/*
 * vote_se add function
 */
$info = '投票选项编辑';
if (isset ($_POST['submit'])) {
    $id=$id;
	$vote_id = $_POST['vote_id'];
	$se_id = $_POST['se_id'];
	$contant = $_POST['contant'];
	$line = $vote->vote_add($id, $se_id, $vote_id, $contant, 3, 0);
	if ($line) {
		$info = '更新成功';
	} else {
		$info = '更新失败';
	}
}
/*
 * set template
 */
$smarty->assign('vote_se', $votes);
$smarty->assign('topic', $topics);
$smarty->assign('info', $info);
$smarty->display("vote_edit1.html");
?>
